ENT.Base = "base_brush"
ENT.Type = "brush"

ENT.CheckPoint = 0

function ENT:Initialize()
	GAMEMODE.CheckPoints[self.CheckPoint] = self
	GAMEMODE.NumCheckPoints = #GAMEMODE.CheckPoints

	if self.CheckPoint == 2 then
		local first = GAMEMODE.CheckPoints[1]
		local normal = self:LocalToWorld(self:OBBCenter()) - first:LocalToWorld(first:OBBCenter())
		local corrected = normal:Angle()
		GAMEMODE.SpawnAngle = Angle(0, math.NormalizeAngle(corrected.y - 90), 0)
	end
end

function ENT:KeyValue(key, value)
	if key == "number" then
		self.CheckPoint = tonumber(value)
	end
end

function ENT:StartTouch( entity )
	if !self:PassesTriggerFilters( entity ) then return end

	if entity:IsPlayer() && !entity:InVehicle() then
		entity:Kill()
	elseif entity:IsVehicle() then
		GAMEMODE:PassCheckpoint(entity, self)
	end
end

function ENT:PassesTriggerFilters( entity )
	return entity:IsPlayer() || entity:IsVehicle()
end